﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TjZheng.Framework;

namespace TjZheng.Example.MVC.Controllers
{
    public class HttpController : Controller
    {
        public ActionResult Get()
        {
            return View();
        }
        public ActionResult GetJson()
        {
            return Json(new InvokeResult(), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult PostData(string data1, string data2)
        {
            ViewBag.Data1 = data1;
            ViewBag.Data2 = data2;
            return View();
        }
        [HttpPost]
        public ActionResult PostDataJson(string data1, string data2)
        {
            return Json(new InvokeResult());
        }
        [HttpPost]
        public ActionResult PostJson(InvokeResult objInvokeResult)
        {
            return View(objInvokeResult);
        }
        [HttpPost]
        public ActionResult PostJsonJson(InvokeResult objInvokeResult)
        {
            return Json(objInvokeResult);
        }
        [HttpPost]
        public ActionResult PostFile()
        {
            string filename = "不存在上传文件";
            var file = Request.Files["photo"];
            if (file != null)
            {
                filename = file.FileName;
            }
            return View("PostFile", new InvokeResult { ResultMessage = filename });
        }
        [HttpPost]
        public ActionResult PostFileJson()
        {
            string filename = "不存在上传文件";
            var file = Request.Files["photo"];
            if (file != null)
            {
                filename = file.FileName;
            }
            return Json(new InvokeResult { ResultMessage = filename });
        }

        public ActionResult WithCookieJson()
        {
            string cookieValue = "没有Cookie";
            var objHttpCookie = "myCookie".GetCookie();
            if (objHttpCookie != null)
            {
                cookieValue = objHttpCookie.Value;
            }
            return Json(new InvokeResult { ResultMessage = cookieValue }, JsonRequestBehavior.AllowGet);
        }
    }
}
